########################################################################
# Generic Makefile for RNPL 'f77' application.
#
# Requires following environment variables to be set to appropriate
# values:
#
# RNPL_RNPL 
# RNPL_RNPL_FLAGS
# RNPL_F77 
# RNPL_F77LOAD
# RNPL_F77PP 
# RNPL_FLIBS
#
########################################################################
.IGNORE:

########################################################################
#  NOTE: This Makefile uses the Bourne shell, 'sh'
########################################################################
SHELL = /bin/sh

########################################################################
#  Set 'APP' to application name stem (prefix) then execute
#  'make fix' to convert Makefile to use explicit targets
########################################################################
APP        =  WKG

########################################################################
# If your application uses headers and/or libraries from 
# non-system locations, define the following macros appropriately ...
# (set to white-space separated path names, don't use 'csh' ~ notation
# for home directories)
########################################################################
USER_INC_PATHS =
USER_LIB_PATHS = 

########################################################################
# If you want to set non-default flags for the 'f77' compiler, do so
# here
########################################################################
RNPL      = $(RNPL_RNPL)

F77       = $(RNPL_F77)
F77_LOAD  = $(RNPL_F77LOAD)
F77PP     = $(RNPL_F77PP)
FLIBS     = $(RNPL_FLIBS)

.f.o:
	$(F77) -c $*.f

all: WKG WKG_init

fix: Makefile
	sed "s@wWKG@WKG@g" < Makefile > .Makefile 
	mv .Makefile Makefile

INCS = metricandsource.inc
WKG.f:      WKG_rnpl  $(INCS)
	$(RNPL) -l allf  WKG_rnpl
	rnpl_fix_f77 updates.f residuals.f initializers.f

updates.f:     WKG_rnpl
residuals.f:     WKG_rnpl
initializers.f:     WKG_rnpl
WKG_init.f: WKG_rnpl

WKG_init: WKG_init.o updates.o initializers.o residuals.o
	$(F77_LOAD) WKG_init.o updates.o residuals.o initializers.o $(FLIBS) -o WKG_init

WKG: WKG.o updates.o residuals.o
	$(F77_LOAD) WKG.o updates.o residuals.o $(FLIBS) -o WKG

clean: 
	rm *.hdf *.sdf .rn*  WKG  WKG_init > /dev/null 2>&1
	rm *.o > /dev/null 2>&1
	rm residuals.f updates.f initializers.f WKG.f WKG_init.f > /dev/null 2>&1
	rm gfuni0.inc globals.inc other_glbs.inc sys_param.inc > /dev/null 2>&1
	rm flux.txt > /dev/null 2>&1
	rm work.pc work.pcl > /dev/null 2>&1
